#include "./include/foodmenu.h"

void foodmenu_add(struct pointlist *pl_head, char *p_name, int price, int remain, char *p_comment, int time)
{
	FOODMENU_DECLARE(fm_tail);
	FOODMENU_DECLARE(fm_new);
	FOODMENU_GETMEM(fm_new);
	if(POINTLIST_IS_EMPTY(pl_head))
	{
		fm_new->foodid = 1;
	}
	else
	{
		fm_tail = POINTLIST_TO_ITEM(pl_head->prev, struct foodmenu, pointer);
		fm_new->foodid = fm_tail->foodid + 1;
	}
	strcpy(fm_new->name, p_name);
	fm_new->price = price;
	fm_new->remain = remain;
	strcpy(fm_new->comment, p_comment);
	fm_new->time = time;
	fm_new->flag = sizeof(struct foodmenu);
	
	pointlist_add_tail(pl_head, &fm_new->pointer);
}

//节点遍历
void foodmenu_show_foreach(struct pointlist *pl_head)
{
	struct pointlist *pl_tmp = NULL;
	struct foodmenu *fm_tmp = NULL;
	
	POINTLIST_FOR_EACH(pl_tmp, pl_head)
	{
		fm_tmp = POINTLIST_TO_ITEM(pl_tmp, struct foodmenu, pointer);
		foodmenu_show(fm_tmp);
	}
}

//打印节点信息
void foodmenu_show(struct foodmenu *fm_tmp)
{
	printf("%02d ", fm_tmp->foodid);
	printf("%s\t", fm_tmp->name);
	printf("%d\t", fm_tmp->price);
	printf("%d\t", fm_tmp->remain);
	printf("%s\t", fm_tmp->comment);
	printf("%d\t", fm_tmp->time);
	printf("\n");
}

//搜索节点
void foodmenu_searchid(struct foodmenu *fm_tmp)
{
	return;
}